/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2024 AUTHOR,AFFILIATION
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Application
    monitorPatch

Description

\*---------------------------------------------------------------------------*/

#include "fvCFD.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    // #include "createMesh.H"
    Foam::Info
     << "tttt: Create mesh for time = "
     << runTime.timeName() << Foam::nl << Foam::endl;
 
    Foam::fvMesh mesh
    (
        Foam::IOobject
        (
            Foam::fvMesh::defaultRegion,
            runTime.timeName(),
            runTime,
            Foam::IOobject::MUST_READ
        )
    );
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    const List<word> patchNameList = {"front", "back"};

    forAll(patchNameList, patchI)
    {
        label patchId = mesh.boundary().findPatchID(patchNameList[patchI]);
        Info << "Dealing with: " << patchNameList[patchI]
             << " With patchId: " << patchId
             << endl;
    }

    instantList timeDirs = timeSelector::select0(runTime, args);
    const dimensionedScalar myTimeStep(
        "myTimeStep",
        dimensionSet(0, 0, 1, 0, 0, 0, 0),
        1e-6  // NOTE: Assign your value
    );

    scalar latestTime = timeDirs.last().value();
    Info << "The latestTime of present case: " << latestTime << endl;


    forAll(timeDirs, timei)
    {
        // NOTE: 避免超出算例中的最大时刻的时间文件
        if(runTime.value() != latestTime){
            runTime += myTimeStep;
        }
                
        Info << "Time = " << runTime.timeName() << endl;

        volScalarField p
            (
                IOobject
                (
                    "p",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
                ),
                mesh
            );

        Info << "Use p[0] to test " << p[0] << endl;
        Info<< nl;
    }

    //
        volScalarField p_rgh
            (
                IOobject
                (
                    "p_rgh",
                    "2.1e-5",
                    mesh,
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
                ),
                mesh
            );    
        Info << "p_rgh[0]: " << p_rgh[0] << endl;

    Info<< nl;
    runTime.printExecutionTime(Info);

    Info<< "End\n" << endl;

    return 0;
}


// ************************************************************************* //
